BASE_URL='/';//根目录

/**去除2边函数**/
function str_trim(str){ //删除左右两端的空格
    return str.replace(/(^[\s\,\-\+\，\#]*)|([\s\,\-\+\，\#]*$)/g, "");
}

//实现hashtable去掉重复项
function array_unique(arr) {
    var result = [], hash = {};
    for (var i = 0, elem; (elem = arr[i]) != null; i++) {
        if (!hash[elem]) {
            result.push(elem);
            hash[elem] = true;
        }
    }
    return result;
//http://www.cnblogs.com/sosoft/
}
//判断数组是不是重复项
function isUnique(arr){
    var hash = {};
    for(var i in arr) {
        if(hash[arr[i]])
            return true;
        hash[arr[i]] = true;
    }
    return false;
}
/**
 * 设置一下cookie
 * @param name 名称
 * @param value 值
 * @param days 保存的时间null代表关闭失效
 */
function setCookie(name, value, days){
    if(days == null){
        document.cookie = name + "=" + value + ";path=/";
    }else{
        var exp = new Date();
        exp.setTime(exp.getTime() + days * 24 * 60 * 60 * 1000);
        document.cookie = name + "=" + value + ";path=/" + ";expires=" + exp.toGMTString();
    }
}
/**
 * 获取一个cookie
 * @param name cookie名称
 * @returns {*}
 */
function getCookie(name){
    var strArg = name + "=";
    var nArgLen = strArg.length;
    var nCookieLen = document.cookie.length;
    var nEnd;
    var i = 0;
    var j;
    while(i < nCookieLen){
        j = i + nArgLen;
        if(document.cookie.substring(i, j) == strArg){
            nEnd = document.cookie.indexOf(";", j);
            if(nEnd == -1) nEnd = document.cookie.length;
            //return decodeURIComponent(document.cookie.substring(j,nEnd));
            return document.cookie.substring(j, nEnd);
        }
        i = document.cookie.indexOf(" ", i) + 1;
        if(i == 0) break;
    }
    return null;
}
/**
 * Created by Administrator on 2016/8/12.
 * 公共函数库
 */
//截取中文
function mSubstr(str,size){
    var totalCount = 0;
    var newStr = "";
    for (var i=0; i<=str.length; i++) {
        var c = str.charCodeAt(i);
        if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) {
            totalCount++;
        }else {
            totalCount+=2;
        }
        if(totalCount<size){
            newStr = str.substring(0,i+1);
        }else{
            return newStr+"...";
        }
    }
    return newStr;
}
//判断数组是不是存在
function in_array(search,array){
    for(var i in array){
        if(array[i]==search){
            return true;
        }
    }
    return false;
}

/**jquery添加select option**/
function jqueryAddOption(obj,arr,othisobj){
    $.each(arr, function(key, value) {
        $('#'+othisobj).find("#"+obj).append($("<option/>", {
            value: value['value'],
            text: value['text']
        }));
    });
}

/**radio的选择*/
function radio_checked(m,myvalue){
    for(var i=0;i<m.length;i++){
        if(m[i].value==myvalue){
            m[i].checked=true;
        }
    }
}

/**@parem //content 内容
 * time 几秒关闭
 * */
function layerMsg(content,time){
    layer.open({
        content:content,
        skin:'msg',
        time:time,
        style:'font-size:.28rem; line-height: .3rem; margin:auto;bottom:0; font-family:Microsoft Yahei; padding:0.15rem 0.12rem; z-index:99999999'
    });
}


